<?php
 defined("BASEDIR") or die();
 
 class Application_Router_Standard_Route implements Application_Interface_FrontController
 {
	protected static $instance;
        protected $controllerFilePath, $controllerFileType;
	
	protected function __construct()
	{
		$this->controllerFilePath = "Application_Controller_";
		$this->controllerFileType = ".php";
	}
	private function __clone()
	{
		return false;
	}
	public static function getInstance()
	{
		if(!self::$instance instanceof self)
			self::$instance = new self;
		return self::$instance;
	}
	
	public function dispatch(Application_Router_Standard_Request $request)
	{
		$db = Application_Model_DataBase::getInstance();
		$ses = Application_Model_SessionControl::getInstance();
		$user = Application_Router_Standard_User::getInstance($request);
		$view = Application_View_ViewEngine::getInstance();
				
		
		
		if($request->controller == "adminpanel" )
		{
			$controller = new Application_Controller_Adm_Default($request);
		}
		
		else
		{
			if($ses->logged_in == true)
			{
			}
			if($request->controller != "")
			{
				$controllerName = $this->controllerFilePath.ucfirst($request->controller);
				if(is_readable("../application/controller/".$request->controller.".php"))
					$controller = new $controllerName($request);
				else
					$this->defaultDispatch($request);
			}
			else
			{
				$this->defaultDispatch($request);
			}
		}
	}
	public function defaultDispatch(Application_Router_Standard_Request $request)
	{
	
		$ses = Application_Model_SessionControl::getInstance();
		//if($ses->logged_in) $request->controller = "news";
		//else 
		$request->controller = "home";
		$controllerName = $this->controllerFilePath.ucfirst($request->controller);
		$controller = new $controllerName($request);
		
	}
 }
?>